package com.sunfeng.chap2;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 验证read(ByteBuffer dst)方法从通道读取数据大于缓冲区容量
 */
public class Test2_5 {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(new File("d:\\abc.txt"));
        FileChannel channel = fileInputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate(3);
        System.out.println(channel.position());

        // 通道数据量大于remind
        channel.read(byteBuffer);
        System.out.println(channel.position());
        channel.close();
        fileInputStream.close();

        byteBuffer.rewind();

        for (int i = 0; i < byteBuffer.limit(); i++) {
            System.out.print((char) byteBuffer.get()+" ");
        }

    }
}
